package com.xintong.visualinspection.service.impl;

import java.util.List;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xintong.visualinspection.bean.CheckItem;
import com.xintong.visualinspection.bean.CheckRule;
import com.xintong.visualinspection.dao.master.CheckRuleDao;
import com.xintong.visualinspection.service.BaseService;
import com.xintong.visualinspection.service.CheckRuleService;

/**
 * 文件名：UserServiceImpl
 * 版本信息：日期：2017/3/30 Copyright 江苏省交通规划设计院 Corporation 2017 版权所有.
 */
@Service
public class CheckRuleServiceImpl extends BaseService implements CheckRuleService {

    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CheckRuleServiceImpl.class);


    @Autowired
    private CheckRuleDao checkRuleDao;

	@Override
	public List<CheckRule> getAll() {
		// TODO Auto-generated method stub
		return checkRuleDao.getAll();
	}

	@Override
	public CheckRule getById(Long id) {
		// TODO Auto-generated method stub
		return checkRuleDao.getOne(id);
	}

	@Override
	public List<CheckRule> getByName(String name) {
		// TODO Auto-generated method stub
		return checkRuleDao.getByName(name);
	}

	@Override
	public void insert(CheckRule checkRule) {
		// TODO Auto-generated method stub
		checkRuleDao.insert(checkRule);
		if(checkRule.getCheck_items()!=null && checkRule.getCheck_items().size()>0) {
			Long id = checkRuleDao.getLastId();
			for(CheckItem item:checkRule.getCheck_items()){
				item.setRule_id(id);
			}
			checkRuleDao.insertRuleItem(checkRule.getCheck_items());
		}
	}

	@Override
	public void update(CheckRule checkRule) {
		// TODO Auto-generated method stub
		checkRuleDao.update(checkRule);
		checkRuleDao.deleteRuleItem(checkRule.getId());
		if(checkRule.getCheck_items()!=null && checkRule.getCheck_items().size()>0) {
			Long id = checkRule.getId();
			for(CheckItem item:checkRule.getCheck_items()){
				item.setRule_id(id);
			}
			checkRuleDao.insertRuleItem(checkRule.getCheck_items());
		}
	}

	@Override
	public void delete(Long id) {
		// TODO Auto-generated method stub
		checkRuleDao.delete(id);
	}
}
